-
Notifications
You must be signed in to change notification settings - Fork 73
refactor: Afterpay payment method definition #11174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
refactor: Afterpay payment method definition #11174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the Afterpay/Clearpay payment method from the legacy Afterpay_Payment_Method class to a new AfterpayDefinition class, following the modern payment method definition pattern established in a previous refactoring (PR #11138 for Affirm).
Key Changes
- Introduced new
AfterpayDefinitionclass implementingPaymentMethodDefinitionInterface - Removed legacy
Afterpay_Payment_Methodclass and all its references - Removed special initialization hook that updated payment method properties based on account country (no longer needed with the new definition approach)
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
includes/payment-methods/Configs/Definitions/AfterpayDefinition.php |
New payment method definition class with country-specific logic for US (Cash App Afterpay), UK (Clearpay), and other regions |
includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php |
Registered AfterpayDefinition in the payment method registry |
includes/payment-methods/class-afterpay-payment-method.php |
Removed legacy payment method class |
includes/class-wc-payments.php |
Removed legacy class import and instantiation references |
includes/class-wc-payment-gateway-wcpay.php |
Removed special country-based initialization hook and legacy class references; Afterpay now added via definition registry |
includes/class-duplicates-detection-service.php |
Removed hardcoded 'afterpay' and 'clearpay' keywords; now handled by definition's get_keywords() method |
tests/unit/test-class-wc-payment-gateway-wcpay.php |
Updated test to use AfterpayDefinition instead of Afterpay_Payment_Method |
tests/unit/payment-methods/test-class-upe-payment-method.php |
Updated test to use AfterpayDefinition instead of Afterpay_Payment_Method |
tests/unit/payment-methods/test-class-upe-payment-gateway.php |
Updated test to use AfterpayDefinition instead of Afterpay_Payment_Method |
changelog/refactor-afterpay-clearpay-payment-method-definition |
Added changelog entry for this refactoring |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
|
Size Change: +1 B (0%) Total Size: 877 kB
ℹ️ View Unchanged
|
| public function maybe_update_properties_with_country(): void { | ||
| if ( Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID !== $this->stripe_id ) { | ||
| return; | ||
| } | ||
| $account_country = $this->get_account_country(); | ||
| $this->icon = $this->payment_method->get_icon( $account_country ); | ||
| $this->title = $this->payment_method->get_title( $account_country ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was being executed only for Afterpay.
It was needed because when the payment method was initialized, we needed to ensure its icon/title matched the correct country.
But it's no longer needed.
| #radio-control-wc-payment-method-options-woocommerce_payments_afterpay_clearpay__label | ||
| img { | ||
| min-width: 64px; | ||
| height: auto; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Co-authored-by: Copilot <[email protected]>


Changes proposed in this Pull Request
Converting the Afterpay/Clearpay payment method class into the newer payment method definition class - similar to how it's been done in #11138
Testing instructions
npm run changelogto add a changelog file, choosepatchto leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge